package com.yalu.service.data.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.yalu.dao.data.ExpressfeesDao;
import com.yalu.entity.base.BaseEntity;
import com.yalu.entity.data.Expressfees;
import com.yalu.entity.data.ExpressfeesKey;
import com.yalu.service.base.impl.BaseServiceImpl;
import com.yalu.service.data.ExpressfeesService;
import com.yalu.util.BaseUtil;

@Service
public class ExpressfeesServiceImpl extends BaseServiceImpl<Expressfees, ExpressfeesKey>
implements ExpressfeesService {

	@Resource
	private ExpressfeesDao expressfeesDao;

	@Resource
	public void setBaseDao(ExpressfeesDao expressfeesDao) {
		super.setBaseDao(expressfeesDao);
	}

	@Override
	public int[] save(List<BaseEntity> entityList) {
		System.err.println("====ExpressfeesServiceImpl save");
		int[] returnCounts = new int[2];
		int saveCount = 0;
		int updateCount = 0;
		String time = BaseUtil.getTime();
		//		for (BaseEntity baseEntity : entityList) {
		//			ShopAttribute entity = (ShopAttribute) baseEntity;
		//			entity.getShopAttributeKey().setCreatedt(time);
		//			shopAttributeDao.save(entity);
		//			saveCount++;
		//		}

		for(BaseEntity baseEntity : entityList){
			Expressfees entity = (Expressfees)baseEntity;
			ExpressfeesKey key  = entity.getExpressfeesKey();
			Expressfees temp = expressfeesDao.get(key);
			if(temp==null){
				entity.setCreatedt(time);
				expressfeesDao.save(entity);
				saveCount++;
			}else{
				entity.setUpdatedt(time);
				BeanUtils.copyProperties(entity,temp, new String[] { "createdt",
						"createby", "updateby" });
				expressfeesDao.update(temp);
				updateCount++;
			}
		}

		returnCounts[0] = saveCount;
		returnCounts[1] = updateCount;
		return returnCounts;
	}

}
